app.directive('zTree', [
	'$timeout',"$animate", function($timeout,$animate) {
		return {
			restrict: 'A',
			templateUrl: function(e,attr) {
				return attr.template;
			},
			replace: true,
			scope: {
				treeData: '=',
				useToggle: '@',
				mouseEnterClass : "=",
				onSelect: '&',
				onDblclick : '&',
				initialSelection: '@',
				treeShowCheckbox  : '=',
				ctrlRef: '=',
				templateFile:'='
			},
			controller: function($scope, $element){
				$scope.onClick = function(scope) {
					$scope.select = scope.$id;
					scope.onSelect({node:scope.$modelValue});
//	            	scope.toggle();
				}
				$scope.onDblClick = function(scope) {
					scope.onDblclick({node:scope.$modelValue});
				}
	        },
			link: function(scope, element, attrs) {
				scope.treeShowCheckbox;
				scope.useToggle = true;
				scope.activeNodeScope = {};
				scope.oldActiveNodeScope = {};
				scope.checked_change = function(branch,event) {
					debugger;
					branch.checked = !branch.checked;
					event.stopPropagation();
				};
				
				scope.$watch('activeNodeScope',function(newNodeScope,oldNodeScope) {
					scope.oldActiveNodeScope = oldNodeScope;
					oldNodeScope.active = false;
					newNodeScope.active = true;
				});
				
				scope.$watch('useToggle',function(newValue) {
					if(newValue == undefined) {
						scope.useToggle = true;
					}
				});
				
				scope.$watch('treeData', function() {
					$timeout(function(){
//						debugger;
						if(scope.mouseEnterClass) {
							element.find("a").addClass(scope.mouseEnterClass);
							element.find("a").off("mouseenter mouseleave");
							element.find("a").on("mouseenter mouseleave",function (event) {
								if(event.type=="mouseenter") {
									$animate.addClass($(this), "mouseenter");
								} else {
									$animate.removeClass($(this), "mouseenter");
								}
							});
						}
						
						eachTreeScope(scope.$$childHead.$nodesScope,function(nodeScope) {
							nodeScope.active = false;
						});
					},0)
				}, true);
				
				var eachTreeScope = function(nodesScope,fn) {
					var arr = nodesScope.$modelValue;
					var map = nodesScope.$nodesMap;
					if(arr!=undefined) {
						for(var i=0;i<arr.length;i++) {
							var ns = map[arr[i].$$hashKey];
							var ret = fn(ns);
							if(ret == "return") {
								return ret;
							} else if (ret == "continue") {
								continue;
							} else if (ret == "break") {
								break;
							}
							var eachRet = eachTreeScope(ns.$childNodesScope,fn);
							if(eachRet == "return") {
								return eachRet;
							}
						}
					}
				}
				var findScope = function(nodeScope,parentNodeScope) {
					if(!parentNodeScope) {
						parentNodeScope = scope.$$childHead.$nodesScope;
					}
					var ns;
					eachTreeScope(parentNodeScope.$childNodesScope,function(eachNodeScope) {
						if(eachNodeScope == nodeScope) {
							ns = eachNodeScope;
							return "return";
						}
					});
					return ns;
				}
//				var toggleSameLevel = function(nodeScope) {
//					eachTreeScope(nodeScope.$parent.$parent,function(eachNodeScope) {
//						if(eachNodeScope != cs && eachNodeScope.collapsed != true) {//如果是关着的，就不能开
//							eachNodeScope.toggle();
//						}
//						return "continue";
//					});
//				};
				
				var eachSameLevelScope = function(nodeScope,fn) {
					if(nodeScope.$parentNodesScope) {
						var parentNodeScope = nodeScope.$parentNodesScope;
						var arr = parentNodeScope.$modelValue;
						var map = parentNodeScope.$nodesMap;
						if(arr!=undefined) {
							for(var i=0;i<arr.length;i++) {
								var ns = map[arr[i].$$hashKey];
								var ret = fn(ns);
								if(ret == "return") {
									return ret;
								} else if (ret == "continue") {
									continue;
								} else if (ret == "break") {
									break;
								}
							}
						}
					}
				}
				
				var eachParentScope = function(nodeScope,fn) {
					if(nodeScope.$parentNodeScope) {
						var ret = fn(nodeScope.$parentNodeScope);
						if(ret == "return") {
							return ret;
						}
						var eachRet = eachTreeScope(nodeScope.$parentNodeScope,fn);
						if(eachRet == "return") {
							return eachRet;
						}
					}
				}
				var getScopeByData = function(data) {
					var ns;
					eachTreeScope(scope.$$childHead.$nodesScope,function(nodeScope) {
						if(nodeScope.$modelValue == data) {
							ns = nodeScope;
							return "return";
						}
					});
					return ns;
				}
				
				if (scope.ctrlRef != null) {
					if (angular.isObject(scope.ctrlRef)) {
						var tree = scope.ctrlRef;
						
						tree.toggle = function(data) {
							var cs = getScopeByData(data);
							if(cs.collapsed) {//进行展开的操作
								if(scope.useToggle) {//使用互斥
									if(findScope(scope.oldActiveNodeScope,cs)==undefined) {
										cs.collapseAll();
										eachSameLevelScope(cs,function(ns) {//查找同级的菜单，哪一个菜单的自己含有激活菜单，如果有，将同级菜单变为激活并收起
											if(findScope(scope.activeNodeScope,ns)!=undefined) {
												scope.activeNodeScope = ns;
											}
										});
									} else {
										if(cs == scope.activeNodeScope) {//如果展开的子集包含激活菜单，则将原有的激活再归还给子集
											scope.activeNodeScope = scope.oldActiveNodeScope;
										}
										eachTreeScope(cs.$parent.$parent,function(nodeScope) {//关掉同级展开的节点
											if(nodeScope.collapsed != true) {//如果是关着的，就不能开
												nodeScope.toggle();
											}
											return "continue";
										});
									}
								}
								if(data.children == undefined||data.children.length == 0) {//叶子节点
									scope.activeNodeScope = cs;
								} else {
								}
								//展开父级
								eachParentScope(cs,function(parentScope) {
									if(parentScope.collapsed) {//如果是开着的，就不能关掉
										parentScope.toggle();
									}
									return "continue";
								})
							} else {//进行关闭
								if(findScope(scope.activeNodeScope,cs)!=undefined) {//查找激活选项是否在自己的子集，如果有，则把自己变为激活选项
									scope.activeNodeScope = cs;
								}
							}
							cs.toggle();
						}
						
						tree.expand_all = function(data) {
							if(data) { //在nodeMapper中查找
								var _scope = getScopeByData(data);
								_scope.expandAll();
//								return $scope.$$childHead.$nodesScope.$modelValue;
							} else {
								scope.$$childHead.expandAll();
//								scope.$$childHead.$nodesScope.$broadcast('expandAll');
//								return scope.$$childHead.$nodesScope.$modelValue;
							}
						};
						tree.collapse_all = function(data) {
							if(data) { //在nodeMapper中查找
								var _scope = getScopeByData(data);
								_scope.collapseAll();
//								return $scope.$$childHead.$nodesScope.$modelValue;
							} else {
								scope.$$childHead.collapseAll();
//								return scope.$$childHead.$nodesScope.$modelValue;
							}
						};
						tree.add_branch = function(parentData, newData) {
							if (parentData != null) {
								if(parentData.children!=null&&parentData.children!=undefined){
									parentData.children.push(newData);
								}else{
									parentData.children = [];
									parentData.children.push(newData);
								}
							} else {
								scope.treeData.push(newData);
							}
//							return new_branch;
						};
						tree.add_root_branch = function(new_branch) {
							tree.add_branch(null, new_branch);
//							return new_branch;
						};
						tree.del_branch = function(data) {
							var parentData = tree.get_parent_branch(data);
							if(parentData) {
								parentData.children.splice($.inArray(data,parentData.children),1);
							}else{
								scope.treeData.splice($.inArray(data,scope.treeData),1);
							}
//							return b;
						}
						tree.get_parent_branch = function(data) {
							var scope = getScopeByData(data);
							if(scope) {
								if(scope.$parentNodesScope.$nodeScope==null){
									return null;
								}
								return scope.$parentNodesScope.$nodeScope.$modelValue;
							}
							return null;
						}
					}
				}
			}
		};
	}
]);

app.directive('zTabs', [
	'$http','$compile', function($http,$compile) {
		return {
			restrict: 'A',
			templateUrl: "static/html/directives/tabsTemplate.html",
			replace: true,
			scope: {
				tabsData: '=',
				onSelect: '&',
				ctrlRef: '=',
				currentPage: '=',//从外部向内变更
				changeCurrentPageFn: '&'//通过tab切换标签相应事件的回调
			},
			link: function(scope, element, attrs, controller) {
				var webPageDir = "./static/html/";
				var suffix = ".html";
				var tabsDom = element.find(".nav-tabs");
				var contentDom = element.find(".tab-content");

				if (scope.ctrlRef != null) {
					if (angular.isObject(scope.ctrlRef)) {
						var tabs = scope.ctrlRef;
						tabs.openPage = function(page) {
							if(page) {
								var url = page.url;
								//如果该页面已经打开，则设置为选中
								if(getPageByUrl(url)) {
									setSelect(page);
								} else {//如果该页面没打开，则添加到页面数据源
									scope.tabsData.push(page);
								}
							}
						}
						tabs.closePage = function(page) {
							if(page) {
								var url = page.url;

								if(getPageByUrl(url)) {
									scope.tabsData.splice(getIndex(page),1);
								}
							}
						}
					}
				}

				var _allPages = [];
				var dataChangeHandle = function() {
					if(!scope.tabsData) {
						scope.tabsData = [];
					}
					var _oldAllPage = [];
					angular.extend(_oldAllPage,_allPages);

					for(var a = 0;a<scope.tabsData.length;a++) {
						var has = false;
						for(var b = 0;b<_oldAllPage.length;b++) {
							if(_oldAllPage[b].url == scope.tabsData[a].url) {
								has = true;
								_oldAllPage.splice(b,1);
								break;
							}
						}
						if(!has) {
							//在原有数据源中没找到，则添加
							addTab(scope.tabsData[a]);
						}
					}

					//将老数据源中不存在于新数据源的页关闭
					for(var j = 0;j<_oldAllPage.length;j++) {
						removeTab(_oldAllPage[j]);
						_oldAllPage.splice(j,1);
						j--;
					}

					angular.extend(_allPages,scope.tabsData);
				}
				var currentPageChangeHandle = function() {
					tabs.openPage(scope.currentPage);
				}
				/**
				 * 根据url获取页面对象
				 */
				var getPageByUrl = function(url) {
					var length = scope.tabsData.length;
					for(var i = 0;i<length;i++) {
						if(scope.tabsData[i].url==url) {
							return scope.tabsData[i];
						}
					}
					return null;
				}
				/**
				 * 根据页面对象获取索引
				 */
				var getIndex = function(page) {
					var length = scope.tabsData.length;
					for(var i = 0;i<length;i++) {
						if(scope.tabsData[i].url==page.url) {
							return i;
						}
					}
					return -1;
				}

				/**
				 * 增加tab标签页，并将增加的页面设置为当前选择的页面
				 */
				var addTab = function(page,success) {
					var url = filterChar(page.url);
					var title = page.title?page.title:'未命名';
					var url = page.url;

					$http.get(webPageDir + url + suffix).success(function(data, status, headers, config) {
//						debugger;
						var tab = $('<li id=\"tab_' + filterChar(url) + '\">' +
						'<a data-target=\"#content_' + filterChar(url) + '\">' + title + '</a>' +
						//'<button type="button" class="close">×</button>' +
						'</li>').on('click',(function() {
							scope.$apply(function() {
								setSelect(page);
							});
						})).appendTo($(tabsDom[0])).find('span.ui-icon-close').on('Click',function() {

						});
						var content = $('<div class=\"tab-pane fade\" id=\"content_' + filterChar(url) + '\">' + data + '</div>').appendTo($(contentDom[0]));

						//当controller 通过注入加载时
						//var controllerEles = element.find('[ng-controller]');
						//for(var i=0;i<controllerEles.length;i++) {
						//	$(controllerEles[i]).data('$ngControllerController',scope.$new());
						//	$(controllerEles[i]).children().data('$ngControllerController',scope.$new());
						//}
						
						$compile( tab )( scope );
						$compile( content )( scope );

						setSelect(page);
						if(success) {
							success();
						}
					}).error(function(data, status, headers, config) {
						// called asynchronously if an error occurs
						// or server returns response with an error status.
					});
				}
				var removeTab = function(page,success) {
					$("#tab_" + filterChar(page.url)).off('click').find('span .ui-icon-close').off('click').remove();
					$("#content_" + filterChar(page.url)).remove();
					debugger;
//					distory();

					if(getIndex(page)-1>=0) {
						setSelect(scope.tabsData[getIndex(page)-1]);
					} else if(getIndex(page)+1>=0) {
						setSelect(scope.tabsData[getIndex(page)+1]);
					}
					if(success) {
						success();
					}
				}
				/**
				 * 设置当前选择的页面，并改变currentPage变量
				 */
				var setSelect = function(page,success) {
					scope.currentPage = page;
					$("#tab_" + filterChar(page.url)).find('a').tab('show');
					//scope.onSelect({page:scope.currentPage});
					/*if(success) {
						success();
					}*/
				}
				var filterChar = function(str) {
					if(str) {
						return (str + "_").replace(/\W/g,'');
					} else {
						return str;
					}

				}
				scope.$watch('tabsData',dataChangeHandle,true);
				scope.$watch('currentPage',currentPageChangeHandle,true)
				//dataChangeHandle();
			}

	};
	}
]);

app.directive('zDisableTextSelect', [ '$timeout', function($timeout) {
	return {
		restrict: 'A',
		link: function(scope, element, attrs, controller) {
			if($.support .mozilla){//Firefox
				element.css('MozUserSelect','none');
			}else if($.support .msie){//IE
				element.bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				element.mousedown(function(){return false;});
			}
		}
		};
} ]);

app.directive('zPagination',['$timeout', function($timeout) {
	return {
		restrict:'A',
		templateUrl: "static/html/directives/paginationTemplate.html",
		replace: true,
		scope: {
			totalData: '=',
			perPage :'=',
			onClick  :'&',
			currentPage :'=',
			onChangePerPage :'&'
		},
		link: function(scope,element,attrs,controller){
			scope.maxSize = 5;
			
			scope.user_change_perPage = function(){
				$timeout(function() {
					scope.onClick({page:scope.currentPage,perPage:scope.perPage});
				});
			};
			scope.user_clicks_page = function(){
				$timeout(function() {
					scope.onClick({page:scope.currentPage,perPage:scope.perPage});
				});
			};
		}
	};
}]);


app.directive('zUpload',['$timeout', function($timeout) {
	return {
		restrict:'A',
		templateUrl: "static/html/directives/uploadTemplate.html",
		replace: true,
		scope: {
			selectFileId: '@',
			tokenUrl:'@',
			uploadUrl:'@',
			multipleFiles:'=',
			onQueueComplete:'&',
			uploadStream: '=',
			uploadFiles:'=',
			autoUploading:'='
		},
		link: function(scope,element,attrs,controller){
			//生成uuid
			var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
			Math.uuid = function (len, radix) {
			    var chars = CHARS, uuid = [], i;
			    radix = radix || chars.length;
			 
			    if (len) {
			      // Compact form
			      for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
			    } else {
			      // rfc4122, version 4 form
			      var r;
			 
			      // rfc4122 requires these characters
			      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
			      uuid[14] = '4';
			 
			      // Fill in random data.  At i==19 set the high bits of clock sequence as
			      // per rfc4122, sec. 4.1.5
			      for (i = 0; i < 36; i++) {
			        if (!uuid[i]) {
			          r = 0 | Math.random()*16;
			          uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
			        }
			      }
			    }
			 
			    return uuid.join('');
			  };
			
			if(!scope.selectFileId){
				scope.selectFileId = Math.uuid();
			}
			if(!scope.multipleFiles){
				scope.multipleFiles = false;
			}
			if(!scope.autoUploading){
				scope.autoUploading = false;
			}
			if(!scope.uploadFiles){
				scope.uploadFiles = false;
			}
			scope.fileList = [];
			scope.select_file_name="";
			scope.Progress = "0%";
			scope.select_file_id = scope.selectFileId;
			//var BASE_PATH = "http://localhost:8080/hr";
			scope.delFile = function(file){
				scope.fileList.splice($.inArray(file,scope.fileList),1);
				scope._t.cancelOne(file.id);
				scope.select_file_name = "已选择"+scope.fileList.length+"个文件";
			};
				var config = {
					enabled: true, /** 是否启用文件选择，默认是true */
					customered: true,
					multipleFiles: false, /** 是否允许同时选择多个文件，默认是false */	
					autoRemoveCompleted: false, /** 是否自动移除已经上传完毕的文件，非自定义UI有效(customered:false)，默认是false */
					autoUploading: scope.autoUploading, /** 当选择完文件是否自动上传，默认是true */
					fileFieldName: "FileData", /** 相当于指定<input type="file" name="FileData">，默认是FileData */
					maxSize: 2147483648, /** 当_t.bStreaming = false 时（也就是Flash上传时），2G就是最大的文件上传大小！所以一般需要 */
					simLimit: 10000, /** 允许同时选择文件上传的个数（包含已经上传过的） */
//					extFilters: [".txt", ".gz", ".jpg", ".png", ".jpeg", ".gif", ".avi", ".html", ".htm"], /** 默认是全部允许，即 [] */
					browseFileId : scope.select_file_id, /** 文件选择的Dom Id，如果不指定，默认是i_select_files */
					browseFileBtn : "<div>请选择文件</div>", /** 选择文件的按钮内容，非自定义UI有效(customered:false) */
					/*dragAndDropArea: "i_stream_dropzone",*/
					//filesQueueId : "i_stream_files_queue", /** 文件上传进度显示框ID，非自定义UI有效(customered:false) */
					//filesQueueHeight : 450, /** 文件上传进度显示框的高，非自定义UI有效(customered:false)，默认450px */
					//messagerId : "i_stream_message_container", /** 消息框的Id，当没有自定义onXXX函数，系统会显示onXXX的部分提示信息，如果没有i_stream_message_container则不显示 */
//					frmUploadURL : "http://customers.duapp.com/fd;", /** Flash上传的URI */
					tokenURL : scope.tokenUrl,//"/upload/uploadToken.do",
			      	uploadURL : scope.uploadUrl,// BASE_PATH+"/upload/upload.do",//"http://customers.duapp.com/upload",//
					uploadFiles:scope.uploadFiles,
					autoUploading:scope.autoUploading,
					onSelect: function(files) {
						//console && console.log("-------------onSelect-------------------");
						//console && console.log(files);
						//console && console.log("-------------onSelect-------------------End");
						//$("#fileName").val(files[0].name);
						
						debugger;
						if(!scope.multipleFiles){
				 			for(var i = 0;i < scope._t.waiting.length;i++) {
				 				if(scope._t) {
				 					debugger;
				 					scope._t.cancelOne(scope._t.waiting[i]);
				 				}
				 			}
				 			scope.$apply(function() {
								scope.select_file_name = files[0].name;
								scope.Progress = "0%";
							});
						}else{
							var file = {};
							file.id = files[0].id;
							file.progress = "0%";
							file.name = files[0].name;
							file.size = files[0].size;
							scope.$apply(function() {
								scope.fileList.push(file);
								scope.select_file_name = "已选择"+scope.fileList.length+"个文件";
							});
						}
					},
					onMaxSizeExceed: function(file) {
						//console && console.log("-------------onMaxSizeExceed-------------------");
						//console && console.log(file);
						//$("#i_error_tips > span.text-message").append("文件[name="+file.name+", size="+file.formatSize+"]超过文件大小限制‵"+file.formatLimitSize+"‵，将不会被上传！<br>");
						//console && console.log("-------------onMaxSizeExceed-------------------End");
					},
					onFileCountExceed : function(selected, limit) {
					},
					onExtNameMismatch: function(info) {
					},
					onAddTask: function(file) {
						
					},
					onUploadProgress: function(file) {
						debugger;
						//console && console.log("-------------onUploadProgress-------------------");
						//console && console.log(file);
						scope.$apply(function() {
						if(!scope.multipleFiles){
								scope.Progress = file.percent+"%";
						}else{
							for(var i = 0;i<scope.fileList.length;i++){
								if(file.id == scope.fileList[i].id){
									scope.fileList[i].progress = file.percent+"%";
								}
							}
						}
						});
						//console && console.log("-------------onUploadProgress-------------------End");
					},
					onStop: function() {
						//console && console.log("-------------onStop-------------------");
						//console && console.log("系统已停止上传！！！");
						//console && console.log("-------------onStop-------------------End");
					},
					onCancel: function(file) {
						//console && console.log("-------------onCancel-------------------");
						//console && console.log(file);
						
						//$("#"+file.id).remove();
						
						//var $total = $("#stream_total_progress_bar");
						//$total.find("div.progress-bar").css("width", file.totalPercent + "%");
						//$total.find("span.stream_total_size").text(file.formatTotalLoaded + "/" + file.formatTotalSize);
						//$total.find("span.stream_total_percent").text(file.totalPercent + "%");
						//console && console.log("-------------onCancel-------------------End");
					},
					onCancelAll: function(numbers) {
						scope.select_file_name = "";
						scope.Progress = "0%";
						//console && console.log("-------------onCancelAll-------------------");
						//console && console.log(numbers + " 个文件已被取消上传！！！");
						//$("#i_error_tips > span.text-message").append(numbers + " 个文件已被取消上传！！！");
						
						//console && console.log("-------------onCancelAll-------------------End");
					},
					onComplete: function(file) {
						scope.$apply(function() {
							if(!scope.multipleFiles){

									scope.select_file_name = $.parseJSON(file.msg).newName;
									scope.newName = $.parseJSON(file.msg).name;
									scope.fileName = file.name;
									scope.attachment = $.parseJSON(file.msg).attachment;
									scope.Progress = "100%";
								
							}else{
								for(var i = 0;i<scope.fileList.length;i++){
									if(file.id == scope.fileList[i].id){
										scope.fileList[i].progress = file.percent+"%";
										if(file.msg){
											scope.fileList[i].fileName = scope.fileList[i].name;
											scope.fileList[i].name = $.parseJSON(file.msg).newName;
											scope.fileList[i].newName = $.parseJSON(file.msg).name;
											scope.fileList[i].attachment = $.parseJSON(file.msg).attachment;
										}
									}
								}
							}
						});
						//console && console.log("-------------onComplete-------------------End");
					},
					onQueueComplete: function(msg) {
						if(!scope.multipleFiles){
							scope.fileList = [];
							var file = {};
							file.name = scope.select_file_name;
							file.fileName = scope.fileName;
							file.newName = scope.newName;
							file.attachment = scope.attachment;
							scope.fileList.push(file);
							scope.onQueueComplete({fileUrl:scope.fileList});
						}else{
							scope.onQueueComplete({fileUrl:scope.fileList});
						}
						//console && console.log("-------------onQueueComplete-------------------");
						//console && console.log(msg);
						//console && console.log("-------------onQueueComplete-------------------End");
					},
					onUploadError: function(status, msg) {
						//console && console.log("-------------onUploadError-------------------");
						//console && console.log(msg + ", 状态码:" + status);
						
						//$("#i_error_tips > span.text-message").append(msg + ", 状态码:" + status);
						
						//console && console.log("-------------onUploadError-------------------End");
					}
				};
				
				$timeout(function(){
					scope._t = new Stream(config);
					if(scope.uploadStream){
						scope.uploadStream = scope._t;
					}
					/** 不支持拖拽，隐藏拖拽框 */
					if (!scope._t.bDraggable) {
						$("#i_stream_dropzone").hide();
					}
					/** Flash最大支持2G */
					if (!scope._t.bStreaming) {
						scope._t.config.maxSize = 2147483648;
					}
			    });   
				
		}
	};
}]);

app.directive('zCellEditor', ['$timeout', function ($timeout) {
	return {
        restrict:'A',
        templateUrl: "static/html/directives/CellEditor.html",
        replace: true,
        scope: {
            onChangeNumber: '&',
            row: '=',
			col: '=',
			extClass: '@'
        },
        link: function(scope,element,attrs,controller){
            scope.maxSize = 5;

            scope.user_change_num = function(obj){
                $timeout(function() {
                	scope.onChangeNumber(obj);
                });
            };

            scope.clearNum = function(obj, attr){
                $timeout(function() {
                    if ( obj[attr] ) {
                        obj[attr] = obj[attr].replace(/\D/g,"");
					}
                });
            };

            scope.equals = function(var1, var2) {
            	var t1 = var1 || "";
            	var t2 = var2 || "";
            	var t3 = (t1 == t2);
            	return t3;
			}
        }
	}
}]);